package _2022.hot100._121_买卖股票的最佳时间;

/**
 * @author： YHSimon
 * @date： 2022-04-28 19:56
 */
public class Solution {

    //记录历史最低
    public int maxProfit2(int[] prices) {
        int ans = 0, len = prices.length;
        int min = prices[0];
        for (int i = 0; i < len; i++) {
            ans = Math.max(ans, prices[i] - min);
            min = Math.min(min, prices[i]);
        }
        return ans;
    }

    public int maxProfit(int[] prices) {
        int ans = 0;

        for (int i = 0; i < prices.length; i++) {
            for (int j = i + 1; j < prices.length; j++) {
                ans = Math.max(ans, prices[j] - prices[i]);
            }
        }
        return ans;
    }


    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.maxProfit2(new int[]{7, 1, 5, 3, 6, 4}));
    }
}
